package Dome01;
/*        System.out.println(stu.weight);
        System.out.println(stu1.weight);
        stu.weight = 0;
        System.out.println(stu.weight);
        System.out.println(stu1.weight);*/
/*        System.out.println(stu);
        System.out.println(stu1);*/
//        Stu stu = new Stu("张三",1);
//        Stu stu1 = (Stu)stu.clone();
//
//        System.out.println(stu.index.i);
//        System.out.println(stu1.index.i);
//        stu1.index.i = 0;
//        System.out.println(stu.index.i);
//        System.out.println(stu1.index.i);
//        System.out.println(animal1 == animal);
//        System.out.println(animal.equals(animal1));


import java.util.Objects;

public class Test {
    public static void main(String[] args){
        Animal animal = new Animal("张三");
        Animal animal1 = new Animal("张三");
        System.out.println(animal.equals(animal1));
    }


}

class Animal {
    String name;

    public Animal(String name) {
        this.name = name;
    }
 /*   @Override
    public boolean equals(Object obj) {
        Animal animal = (Animal) obj;
        return animal.name.equals(this.name);
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Animal animal = (Animal) o;
        return Objects.equals(name, animal.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}

class Index implements Cloneable{
    public int i = 1;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Stu implements Cloneable{

    public String name;
    public int weight;

    Index index = new Index();
    public Stu(String name, int weight) {
        this.name = name;
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "name='" + name + '\'' +
                ", weight=" + weight +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Stu tmp = (Stu) super.clone();
        tmp.index = (Index) this.index.clone();
        return tmp;
    }
}
